package org.cbg.until;

import javax.swing.*;
import javax.swing.plaf.basic.BasicScrollBarUI;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * 自定义滚动条UI
 * 
 * @author Administrator
 * 
 */
public class SrcollPanelUINew extends BasicScrollBarUI {

    private JScrollPane jScrollPane;
    private JButton up, down;

    public SrcollPanelUINew() {
    }

    public SrcollPanelUINew(JScrollPane jScrollPane) {
        this.jScrollPane = jScrollPane;
        /**
         * 调节下拉框滚动速度
         */
        jScrollPane.getVerticalScrollBar().setUnitIncrement(30);
    }

    @Override
    protected void configureScrollBarColors() {

        // 把手
        // thumbColor = Color.BLUE;
        // thumbHighlightColor = Color.BLUE;
        // thumbDarkShadowColor = Color.BLACK;
        // thumbLightShadowColor = Color.YELLOW;
        // 滑道
        // trackColor = UIUtils.Color_BACK;
        // trackColor = Color.black;
        // trackColor = Color.RED;
        // setThumbBounds(0, 0, 3, 10);
        // trackHighlightColor = UIUtils.Color_BACK;

    }

    /**
     * 设置滚动条的宽度
     */

    @Override
    public Dimension getPreferredSize(JComponent c) {
        c.setPreferredSize(new Dimension(8, 180));
        return super.getPreferredSize(c);

    }

    // 重绘滑块的滑动区域背景
    @Override
    public void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {

    		Graphics2D g2 = (Graphics2D) g;
            GradientPaint gp = null;
            // 判断滚动条是垂直的 还是水平的
            if (this.scrollbar.getOrientation() == Adjustable.VERTICAL) {
                // 设置画笔
                gp = new GradientPaint(0, 0, new Color(0x9B8B7A), trackBounds.width, 0, new Color(
                        0x9B8B7A));
            }

            if (this.scrollbar.getOrientation() == Adjustable.HORIZONTAL) {
                gp = new GradientPaint(0, 0, new Color(0x9B8B7A), trackBounds.height, 0, new Color(
                        0x9B8B7A));

            }
            g2.setPaint(gp);
            // 填充Track
            g2.fillRect(trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height);

            if (trackHighlight == BasicScrollBarUI.DECREASE_HIGHLIGHT) {
                this.paintDecreaseHighlight(g);
            }
            if (trackHighlight == BasicScrollBarUI.INCREASE_HIGHLIGHT) {
                this.paintIncreaseHighlight(g);
            }

    }

    @Override
    protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {

        super.paintThumb(g, c, thumbBounds);
        String gdt = "";
        	gdt = "inkImg/tupiankuang/Z1008.png";
        // 把绘制区的x，y点坐标定义为坐标系的原点
        // 这句一定一定要加上啊，不然拖动就失效了
        g.translate(thumbBounds.x, thumbBounds.y);
        // 消除锯齿
        Graphics2D g2 = (Graphics2D) g;
        RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.addRenderingHints(rh);
//        g2.drawImage(new ImageIcon("inkImg/hongmu/2/gundongtiao_副本_副本.png").getImage(), 0, 0, thumbBounds.width,
//                thumbBounds.height, 0, 0, thumbBounds.width, thumbBounds.height, jScrollPane);
        g2.drawImage(new ImageIcon(gdt).getImage(), 0, 0, thumbBounds.width,
                thumbBounds.height, 0, 0, thumbBounds.width, thumbBounds.height, jScrollPane);
    }

    /**
     * 创建滚动条上方的按钮
     */

    @Override
    protected JButton createDecreaseButton(int orientation) {

        up = new JButton();
        up.setBorderPainted(false);
        up.setContentAreaFilled(false);
        up.setBorder(null);
        up.setBounds(0, 0, 0, 0);
        	up.setIcon(new ImageIcon("inkImg/tupiankuang/空.png"));
            up.addMouseListener(new MouseListener() {

                @Override
                public void mouseReleased(MouseEvent e) {
                    up.setIcon(new ImageIcon("inkImg/tupiankuang/空.png"));
                }

                @Override
                public void mousePressed(MouseEvent e) {
                    up.setIcon(new ImageIcon("inkImg/tupiankuang/空.png"));
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    up.setIcon(new ImageIcon("inkImg/tupiankuang/空.png"));

                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    up.setIcon(new ImageIcon("inkImg/tupiankuang/空.png"));

                }

                @Override
                public void mouseClicked(MouseEvent e) {

                }
            });
        return up;

    }

    /**
     * 创建滚动条下方的按钮
     */

    @Override
    protected JButton createIncreaseButton(int orientation) {

    		down = new JButton();
    		down.setBorderPainted(false);
    		down.setContentAreaFilled(false);
    		down.setFocusable(false);
    		down.setBorder(null);
    		down.setBounds(0, 0, 0, 0);
    		down.setIcon(new ImageIcon("inkImg/tupiankuang/691.png"));
    		down.addMouseListener(new MouseListener() {
    			
    			@Override
    			public void mouseReleased(MouseEvent e) {
    				down.setIcon(new ImageIcon("inkImg/tupiankuang/空.png"));
    			}
    			
    			@Override
    			public void mousePressed(MouseEvent e) {
    				down.setIcon(new ImageIcon("inkImg/tupiankuang/空.png"));
    			}
    			
    			@Override
    			public void mouseExited(MouseEvent e) {
    				down.setIcon(new ImageIcon("inkImg/tupiankuang/空.png"));
    				
    			}
    			
    			@Override
    			public void mouseEntered(MouseEvent e) {
    				down.setIcon(new ImageIcon("inkImg/tupiankuang/691.png"));
    				
    			}
    			
    			@Override
    			public void mouseClicked(MouseEvent e) {
    				
    			}
    		});
        return down;

    }

}
